import { OneModal } from '@/components/one-ui';
import { IOneModalRef } from '@/pages/type';
import React, { Ref, useRef, useState } from 'react';
import pageStyles from '@/common/pageLayout.less';
import { Form, message } from 'antd';
import { UploadFormCommon } from '../common/UploadForm';
import { onCloseModalCommon } from '@/utils';
import { TagSelectNew as TagSelect } from '@/components/TagSelectNew';
interface SyncPlanModalAPI {
  onClose: () => void;
}

/**
 * 是否有上会结果【Modal】
 * */
export const SyncPlanModal: React.FC<SyncPlanModalAPI> = ({ onClose }) => {
  /**
   * 表单对象
   * */
  const [syncPlanForm] = Form.useForm();

  /**
   * modal的Ref
   * */
  const SyncPlanModalRef: Ref<IOneModalRef> = useRef(null);

  /**
   * 是否必传附件
   * */
  const [isOpenFile, setIsOpenFile] = useState<boolean>(false);

  /**
   * 确定事件
   * */
  const onModalOk = () => {
    onCloseModalCommon(SyncPlanModalRef);
    message.success('计划下达成功');
  };

  return (
    <OneModal
      open={true}
      getContainer={false}
      ref={SyncPlanModalRef}
      title={'结果录入'}
      onCancel={onClose}
      onOk={onModalOk}

      // confirmLoading={auditPlanLoading}
    >
      <div className={pageStyles['fromView-styles']}>
        <Form labelAlign="right" form={syncPlanForm}>
          <TagSelect
            colSpan={12}
            formLabel={'上会结果'}
            // formRequired={true}
            formName={'isShow'}
            defalultKeys={0}
            radioList={[
              {
                value: 1,
                name: '有',
              },
              {
                value: 0,
                name: '无',
              },
            ]}
            onChange={(key) => {
              setIsOpenFile(Boolean(key));
            }}
          />
          <UploadFormCommon
            form={syncPlanForm}
            // requiredLabel='上会结果'
            label="上会结果附件"
            fileFormName={'needProofURL'}
            spanCol={24}
            inRowProportion={24}
            name={'imageInfo'}
            required={isOpenFile}
            accept={'.xls|.pdf|.doc|.docx'}
            url={'/purchaseNeedController/uploadFile'}
            downloadUrl={'/purchaseNeedController/downloadFile'}
            fileFormDelName={'delLicenceUrl'}
            delFunc={() => {}}
            // uploadSuccessCallback={(url) => onEditTable({ value: url, key: 'needProofURL', type: 'UploadFormCommon', record })}
            maxFile={1}
            defaultFiles={null}
            fieldBusiPath={'purchase/need'}
            // defaultFiles={record && record?.id ? record?.needProofURL : null}
          >
            上传附件
          </UploadFormCommon>
        </Form>
      </div>
    </OneModal>
  );
};
